package com.example.shopcardemo;


import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;
 
public class ShopingCar implements Parcelable{
	

	public final static String SERIALIZABLE_KEY="shopingcarserializablekey";
	public final static String SHOP_ID_KEY="shopidkey";
	public final static String SHOP_IS_ONLINE_PAY="shipisonlinepay";
	
	private String YH="\"";
	/**
	 * 璐墿杞﹀晢鍝佹�绘暟
	 * 锛堢敤浜庡湪搴楅摵椤典笂鏄剧ず鍟嗛摵璐墿杞︿腑淇濆瓨鐨勫晢鍝佹暟閲忥級
	 */
	public int productNumber=0;
	private ArrayList<PurchaseNewBean> goodList;
	
	public ShopingCar() {
		goodList=new ArrayList<PurchaseNewBean>();
	}
	
	public void addGood(PurchaseNewBean good){
		if(!goodList.contains(good)){
			goodList.add(good);
		}
	}
	
	public void removeGood(PurchaseNewBean good){
		if(goodList.contains(good)){
			goodList.remove(good);
		}
	}
	
	public ArrayList<PurchaseNewBean> getAllGoods(){
		return goodList;
	}
	
	public void clearAll(){
		for(PurchaseNewBean good : goodList){
			good.setNumber(0+"");
		}
		goodList.clear();
	}
	
	public String toJsonStirng(){
		
		if(goodList.size()==0){
			return null;
		}
		String json="{";
		
		for (int i = 0; i <goodList.size(); i++) {
			PurchaseNewBean bean=goodList.get(i);
			json+=YH+i+YH+":{"+YH+"product_id"+YH+":"+bean.getProduct_id()+","+YH+"product_num"+YH+":"+bean.getNumber()+","+YH+"unit_price"+YH+":"+YH+bean.getUnit_price()+YH+"}";
			if(i!=goodList.size()-1){
				json+=",";
			}
		}
		json+="}";
		return json;
		
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		
	}
	

}
